﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Microsoft.Practices.EnterpriseLibrary.Common;
using System.Configuration;
using Insifo.BE;

namespace Insifo.DL.Gen
{
    public class DLServidor
    {
        #region  Members
        ConnectionSql _csql = new ConnectionSql();

        /// <summary>
        /// Método obtiene los Origenes de Datos Activos
        /// </summary>
        /// <returns>Devuelve un DataSet</returns>
        public DateTime Fecha()
        {
            DateTime dtFecha = DateTime.Now ;
            SqlDatabase sqlDB = new SqlDatabase("Data Source=SSET001;Initial Catalog=CORE_CIDE_Main;Persist Security Info=True;User ID=sa;Password=sa;");
            DbCommand dbCmd = sqlDB.GetStoredProcCommand("Usp_CIDE_GEN_Servidor_Listar");
            dbCmd.CommandTimeout = CadenaConexion.CommandTimeout;
            try
            {
                using (IDataReader dr = sqlDB.ExecuteReader(dbCmd))
                {
                    while (dr.Read())
                    {
                        dtFecha = DBValue.Get<DateTime>(dr, "Fecha");
                        break;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {                
                //if (dbCmd.Connection.State == ConnectionState.Open)
                    //dbCmd.Connection.Close();
                dbCmd.Dispose();                
            }
            return dtFecha;
        }

        /// <summary>
        /// Verifica si hay Conectividad
        /// </summary>
        /// <returns>Devuelve un bool</returns>
        public bool ExisteConectividad(out string postrMensaje)
        {            
            postrMensaje = string.Empty;
            return _csql.ExisteConectividad(CadenaConexion.Obtener(), out postrMensaje);;
        }

        #endregion  Members
    }
}
